Skip to content

Libptr by env#781

Merged
cjdoris merged 3 commits into
mainfrom
libptr-by-env
Jun 2, 2026
Merged

Libptr by env#781
cjdoris merged 3 commits into
mainfrom
libptr-by-env

Conversation

@cjdoris
Copy link
Copy Markdown
Member

@cjdoris cjdoris commented May 31, 2026

Pass the libptr in juliacall from Python to Julia with an env var instead of by setting a secret variable in Main.

We do this because we can set the env var earlier, in particular, so that PythonCall sees it even if it is loaded during jl_init(), which happens when PythonCall is baked into a system image.

I think this resolves the issue in #773.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 31, 2026

Benchmark Results (Julia v1)

Time benchmarks
main db86116... main / db86116...
basic/@py/pydict/init 0.257 ± 0.053 ms 0.262 ± 0.058 ms 0.983 ± 0.3
basic/@py/pydict/pydel 0.259 ± 0.026 ms 0.26 ± 0.025 ms 0.995 ± 0.14
basic/julia/pydict/init 0.234 ± 0.068 ms 0.233 ± 0.077 ms 1 ± 0.44
basic/julia/pydict/pydel 0.236 ± 0.044 ms 0.238 ± 0.049 ms 0.993 ± 0.28
gc/full 0.655 ± 0.0067 s 0.64 ± 0.0031 s 1.02 ± 0.012
time_to_load 2.24 ± 0.016 s 2.22 ± 0.011 s 1.01 ± 0.0089
Memory benchmarks
main db86116... main / db86116...
basic/@py/pydict/init 5.01 k allocs: 0.0764 MB 5.01 k allocs: 0.0764 MB 1
basic/@py/pydict/pydel 5.01 k allocs: 0.0764 MB 5.01 k allocs: 0.0764 MB 1
basic/julia/pydict/init 4.01 k allocs: 0.0612 MB 4.01 k allocs: 0.0612 MB 1
basic/julia/pydict/pydel 4.01 k allocs: 0.0612 MB 4.01 k allocs: 0.0612 MB 1
gc/full 0 allocs: 0 B 0 allocs: 0 B
time_to_load 0.143 k allocs: 10.6 kB 0.143 k allocs: 10.6 kB 1

@cjdoris
Copy link
Copy Markdown
Member Author

cjdoris commented May 31, 2026

@ncudlenco this PR changes how libptr is passed into julia from python, so it should now be picked up if PythonCall is inited during jl_init, which is the case when it is baked into a sysimage. Could you verify if this change is sufficient to use such a sysimage? I'm hopeful that this is an alternative to #773 that doesn't require any sysimage-specific handling.

@ncudlenco
Copy link
Copy Markdown
Contributor

I can confirm that this works fine as an alternative for #733. Way more elegant than my attempts 🚀

@cjdoris cjdoris merged commit 79e8a44 into main Jun 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants